package cn.prophet.controller;

import cn.prophet.bean.AccountDetailed;
import cn.prophet.bean.OpenAccount;
import cn.prophet.bean.vo.SuperResponseBean;
import cn.prophet.service.AccountDetailedService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("account")
public class AccountDetailedController {
    @Resource
    private AccountDetailedService accountDetailedService;
    @GetMapping("detailed")
    @ResponseBody
    public List<AccountDetailed> getAccountDetailed(@RequestParam(value = "userId",required = true)Long userId){
        return accountDetailedService.getAccountDetailedByUserId(userId);

    }
    @GetMapping("openAccount")
    @ResponseBody
    public SuperResponseBean<OpenAccount> openAccount(@RequestParam(value = "userId",required = true)Long userId, @RequestParam(value = "antiWater",required = true)BigDecimal antiWater, @RequestParam(value = "userName",required = true)String userName, @RequestParam(value = "userPsw",required = true)String userPsw,@RequestParam(value = "withdraw_psw")String withdraw_psw){

        return accountDetailedService.openAccount(userId,antiWater,userName,userPsw,withdraw_psw);
    }
    @GetMapping("inputAccount")
    @ResponseBody
    public Map<String,String> inputAccount(@RequestParam(value = "unique_id",required = true)String unique_id){
        Map<String,String> map = new HashMap<>(3);
        String result = accountDetailedService.inputAccount(unique_id);
        if(result!=null&&!"".equals(result)){
            map.put("code","1");
            map.put("msg","验证成功");
            map.put("account",result);
        }else{
            map.put("code","0");
            map.put("msg","验证失败");
        }

        return map;
    }




}
